package com.ticket.controller.api;

import com.ticket.entity.Player;
import com.ticket.service.IPlayerService;
import com.ticket.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/players")
public class PlayerController {

    @Autowired
    private IPlayerService playerService;

    @GetMapping("/team/{teamId}")
    public Result<List<Player>> getPlayersByTeamId(@PathVariable Long teamId) {
        List<Player> players = playerService.getPlayersByTeamId(teamId);
        return Result.success(players);
    }

    @GetMapping("/{id}")
    public Result<Player> getPlayerById(@PathVariable Long id) {
        Player player = playerService.getById(id);
        if (player == null) {
            return Result.error("球员不存在");
        }
        return Result.success(player);
    }
} 